<template>
  <div class="container">
    <div class="top-bar" :style="{ opacity: visible }">
      <i class="iconfont icon-shangyiyeqianyiye" @click="goBack"></i>
      <h3 class="title">{{ item.title }}</h3>
    </div>

    <div class="main">
      <div class="content">
        <img :src="getImages(item.pic)" alt="" class="cover" />
        <p class="slogo">{{ item.slogo }}</p>
      </div>
    </div>
  </div>
</template>
<script setup>
import { toRefs, watchEffect, ref, onMounted, onUnmounted } from 'vue'
import { useMovieStore } from '../stores/movie'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const { list } = toRefs(useMovieStore())
let id = null
let item = null
const visible = ref(0)
onMounted(() => {
  window.addEventListener('scroll', handleScroll)
})
watchEffect(() => {
  id = route.query.id
  item = list.value.find((item) => item.id == id)
})

function getImages(_url) {
  if (_url !== undefined) {
    let _u = _url.substring(7)
    return 'https://images.weserv.nl/?url=' + _u
  }
}
function goBack() {
  router.back()
}
const handleScroll = () => {
  /* 达到300px滚动条完全显示 */
  var scrollTop = window.scrollY
  var opacity = scrollTop / 300
  if (opacity > 1) {
    opacity = 1
  }
  visible.value = opacity
  console.log(opacity)
}
onUnmounted(()=>{
  window.removeEventListener('scroll',handleScroll)
})
</script>

<style scoped>
@import url('https://at.alicdn.com/t/c/font_4027375_22id101ujlf.css');
.container {
  height: 1000px;
  display: flex;
  flex-direction: column;
}
.top-bar {
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 70px;
  color: #fff;
  background-color: #652e80;
}
.title {
  flex: 1;
  text-align: center;
}
.top-bar i {
  font-size: 45px;
}

.main {
  flex: 1;
}
.content {
  text-align: center;
  padding-top: 100px;
}
.cover {
  width: 400px;
  height: 600px;
}
</style>
